/*
 * Copyright (c) 2020-2030 Sishun.Co.Ltd. All Rights Reserved.
 */
package com.demo.elasticsearch.controller;

import com.demo.elasticsearch.service.ContextServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author ：lvfeilong
 * @version ：
 * @description ：
 * @program ：elasticsearch-study-jd
 * @date ：Created in 2021/6/29 19:59
 */
@RestController
public class ContextController {

    @Resource
    private ContextServiceImpl contextService;

    @GetMapping("/insertEsBySearch/{keyword}")
    public boolean insertEsBySearch(@PathVariable("keyword") String keyword) throws IOException {
        return contextService.insertEsBySearch(keyword);
    }

    @GetMapping("/searchEsByKeyword/{keyword}/{currentPage}/{pageSize}")
    public List<Map<String, Object>> searchEsByKeyword(@PathVariable("keyword") String keyword,
                                                       @PathVariable("currentPage") Integer currentPage,
                                                       @PathVariable("pageSize") Integer pageSize) throws IOException {
        return contextService.searchEsByKeyword(keyword, currentPage, pageSize);
    }

    @GetMapping("/highLightSearch/{keyword}/{currentPage}/{pageSize}")
    public List<Map<String, Object>> highLightSearch(@PathVariable("keyword") String keyword,
                                                     @PathVariable("currentPage") Integer currentPage,
                                                     @PathVariable("pageSize") Integer pageSize) throws IOException {
        return contextService.highLightSearch(keyword, currentPage, pageSize);
    }
}